﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using smp.ButterflyCakes.Models.Data;

namespace smp.ButterflyCakes.Models.FormModels.Order
{
    public class ComponentFlavourModel : IOrderModel
    {
        public ComponentFlavourModel()
        {
            Flavours = new List<ComponentFlavourModelItem>();
        }

        [Required]
        public Guid OrderId { get; set; }

        [Required]
        public Guid ComponentId { get; set; }

        public int NumberOfFlavours { get; set; }

        public List<ComponentFlavourModelItem> Flavours { get; set; }

        public ComponentType ComponentType { get; set; }

        public bool IsCarved { get; set; }

        public SelectItem SelectCakeFlavourTypes { get; private set; }

        public void AddFlavourTypes(List<CakeFlavourTypeItem> types)
        {
            SelectCakeFlavourTypes = new SelectItem("FlavourType", true);
            foreach (var item in types)
            {
                if (ComponentType == ComponentType.CustomCupCakes && !item.IsCompatibleWithCupCakes)
                {
                    SelectCakeFlavourTypes.AddOption(new SelectOption(item.Name, item.Id, false, true, "Not compatible with cup cakes"));
                }
                else if (ComponentType == ComponentType.Custom3DCake && !item.IsCompatibleWith3DCakes)
                {
                    SelectCakeFlavourTypes.AddOption(new SelectOption(item.Name, item.Id, false, true, "Not compatible with 3D cakes"));
                }
                else if (ComponentType == ComponentType.CustomGiantCupCake && !item.IsCompatibleWithGiantCakes)
                {
                    SelectCakeFlavourTypes.AddOption(new SelectOption(item.Name, item.Id, false, true, "Not compatible with giant cup cakes"));
                }
                else if (ComponentType == ComponentType.CustomCake && IsCarved && !item.CanCarve)
                {
                    SelectCakeFlavourTypes.AddOption(new SelectOption(item.Name, item.Id, false, true, "Not compatible with carved cakes"));
                }
                else
                {
                    SelectCakeFlavourTypes.AddOption(new SelectOption(item.Name, item.Id, false));
                }
            }
        }
    }

    public class ComponentFlavourModelItem
    {
        public Guid FlavourId { get; set; }
        public string FlavourTypeName { get; set; }
        public string FlavourName { get; set; }
    }
}
